]> wirehaze git hosting - BOS.git/blob - kernel/testkernels etc/kernel.asm

wirehaze git hosting

Merge commit 'dba047e616f303ce818ba9ac7fb9f8a18a3717d3'
[BOS.git] / kernel / testkernels etc / kernel.asm
1 ;------------------------------------------------------------;
2 ; BOS - test kernel ;
3 ;------------------------------------------------------------;
4 ; ;
5 ; by: Christoffer Bubach, 2003-2005 ;
6 ; http://bos.asmhackers.net/ asmhacker@gmail.com ;
7 ; ;
8 ;------------------------------------------------------------;
9
10 ; 16-bit mem map (seg:off)
11 ; 0x0000:0x0000 -> 0x0000:0x0500 BIOS stuff
12 ; 0x0000:0x0500 -> 0x0000:0x2100 root
13 ; 0x0000:0x2100 -> 0x0000:0x3300 fat
14 ; 0x0000:0x3300 -> 0x0000:0x6c00 14,25kb free space
15 ; 0x0000:0x6c00 -> 0x0000:0x7c00 IDT and GDT (256 desc. eatch)
16 ; 0x0000:0x7c00 -> 0x0000:0x7e00 bootsector
17 ; 0x0000:0x7e00 <- 0x0000:0xffff ~32,5kb stack for boot
18 ; 0x1000:0x0000 -> 0x9000:0xffff 576kb free space
19 ; 0xa000:0x0000 -> ............. VGA mem etc.
20
21 use16
22 org 0x0000
23 jmp start
24
25 include 'realmode/a20.inc'
26 include 'realmode/variables.inc'
27 ;----------------------------------------------------;
28 ; show a message and wait for a key before reboot ;
29 ;----------------------------------------------------;
30 first:
31 mov bp, first16
32 mov ax, 0x1301
33 mov bx, 4
34 mov cx, 19
35 mov dx, 0x0401
36 int 0x10
37
38 mov ah, 0
39 int 0x16
40 ;int 0x19
41 ret
42
43 first16 db 'Now in 16 bit mode.'
44
45
46 ;------------------------------------------;
47 ; starting point of second stage code ;
48 ;------------------------------------------;
49 start:
50 cli
51 mov ax, 0x1000
52 mov ds, ax ; registers.
53 mov es, ax
54 mov ss, ax
55 mov sp, 0xFFFF ; Stack..
56 sti
57
58
59 ;----------------------;
60 ; enable a20 gate ;
61 ;----------------------;
62 a20: ; Enable A20
63 in al, 0x64
64 test al, 2
65 jnz a20
66 mov al, 0xD1
67 out 0x64, al
68 .d6:
69 in al, 0x64
70 and ax, 2
71 jnz .d6
72 mov al, 0xDF
73 out 0x60, al
74
75
76 ;-----------------;
77 ; display message ;
78 ;-----------------;
79 call first
80
81
82 ;------------------------;
83 ; enter 32-bit mode ;
84 ;------------------------;
85 pmode:
86 ; xor ebx, ebx
87 ; mov bx, ds
88 ; shl ebx, 4
89 ; mov [BaseAddOn], ebx
90 ; mov eax, ebx
91
92 ; mov [gdt.BOS_code + 2], ax
93 ; mov [gdt.BOS_data + 2], ax
94 ; mov [gdt.BOS_16code + 2], ax
95 ; mov [gdt.BOS_16data + 2], ax
96
97 ; shr eax, 16
98
99 ; mov [gdt.BOS_code + 4], al
100 ; mov [gdt.BOS_data + 4], al
101 ; mov [gdt.BOS_16code + 4], al
102 ; mov [gdt.BOS_16data + 4], al
103
104 ; mov [gdt.BOS_code + 7], ah
105 ; mov [gdt.BOS_data + 7], ah
106 ; mov [gdt.BOS_16code + 7], ah
107 ; mov [gdt.BOS_16data + 7], ah
108
109 ; add ebx, gdt
110
111 ; mov [gdtr + 2], ebx
112 ; add ebx, idt_start - gdt
113 ; mov [idtr + 2], ebx
114
115 xor ebx,ebx
116 mov bx,ds ; BX=segment
117 shl ebx,4 ; BX="linear" address of segment base
118 mov eax,ebx
119 mov [sys_code_1 + 2],ax ; set base address of 32-bit segments
120 mov [sys_data_1 + 2],ax
121 mov [Real_code_1 + 2],ax ; set base address of 16-bit segments
122 mov [Real_data_1 + 2],ax
123 shr eax,16
124 mov [sys_code_1 + 4],al
125 mov [sys_data_1 + 4],al
126 mov [Real_code_1 + 4],al
127 mov [Real_data_1 + 4],al
128
129 mov [sys_code_1 + 7],ah
130 mov [sys_data_1 + 7],ah
131 mov [Real_code_1 + 7],ah
132 mov [Real_data_1 + 7],ah
133
134 add ebx,gdt ; EBX=linear address of gdt
135 mov [gdtr + 2],ebx
136
137 cli ; Disable interrupts,
138 mov ax,cs
139 mov [RealModeCS],ax
140 lgdt [gdtr] ; Load the GDT descriptor
141
142 mov eax, cr0 ; Copy the contents of CR0 into EAX
143 or eax, 1 ; Set bit 0
144 mov cr0, eax ; Copy the contents of EAX into CR0
145
146 ;jmp 10h:clear_pipe ; Jump to code segment, offset clear_pipe
147
148 ; cli ; set protected mode (32-bit)
149 ; lgdt [gdtr]
150 ; mov eax, cr0
151 ; or eax, 1
152 ; mov cr0, eax
153
154 jmp 0x08:flush
155
156 ;----------------------------------------;
157 ; start of 32-bit area. ;
158 ; flush segments and jump to kernel ;
159 ;----------------------------------------;
160 use32
161 flush:
162 mov eax, 0x10 ; refresh all segment registers
163 mov ds, eax
164 mov es, eax
165 mov fs, eax
166 mov gs, eax
167 mov ss, eax
168 mov esp, 0xfffc
169
170 mov byte [ds:0B8502h], 'P'
171 mov byte [ds:0B8503h], 0x07 ; Assign a color code
172
173 jmp $ ;hang
174
175
176
177 ;--------------------------------;
178 ; global descriptor table (gdt) ;
179 ;--------------------------------;
180 gdt:
181 .null: dw 0x0000, 0x0000, 0x0000, 0x0000
182 .codesel: dw 0xFFFF, 0x0000, 0x9800, 0x00CF
183 .datasel: dw 0xFFFF, 0x0000, 0x9200, 0x00CF
184 gdt_end:
185
186 gdtr:
187 .size: dw gdt_end - gdt - 1
188 .address dd gdt ;+ 0x10000 ; 0x10000 is where we are in mem